package com.xy.controller.admin.system;

import com.xy.api.model.dto.system.MenuDTO;
import com.xy.api.model.request.system.MenuRequest;
import com.xy.api.model.response.R;
import com.xy.api.model.response.Rows;
import com.xy.api.service.system.IMenuService;
import com.xy.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/system/menu")
public class MenuController extends BaseController {

    @Autowired
    private IMenuService menuService;

    @PostMapping("/list")
    public R queryMenuList() {
        Rows<MenuDTO> rows = menuService.queryMenuList();
        return success(rows);
    }

    @PostMapping("/authList")
    public R authMenuList() {
        Rows<MenuDTO> rows = menuService.authMenuList();
        return success(rows);
    }

    @PostMapping("/detail")
    public R queryMenuDetail(@RequestBody MenuDTO request) {
        MenuDTO menuDetail = menuService.queryMenuDetail(request.getId());
        return success(menuDetail);
    }

    @PostMapping("/edit")
    public R editMenu(@RequestBody MenuDTO request) {
        menuService.editMenu(request);
        return success();
    }

    @PostMapping("/delete")
    public R deleteMenu(@RequestBody MenuDTO request) {
        menuService.deleteMenu(request.getId());
        return success();
    }
}
